import { GetAll } from '@/services/crud';
import { Reducer, Effect } from 'umi';

export interface AbpModelType {
    namespace: string;
    state: any;
    effects: {
        getAll: Effect;
    };
    reducers: {
        deal: Reducer<any>;
    };
}
const ResourceGroupModel: AbpModelType = {
    namespace: 'Resource',
    state: {
        items: [],
    },
    effects: {
        * getAll({ payload }, { call, put }) {
            const response = yield call(GetAll, payload, 'Resource');
            yield put({
                type: 'deal',
                payload: response,
            });
        },
    },
    reducers: {
        deal(state, action) {
            var items = [];
            if (action.payload.result) {
                items = action.payload.result.items;
            }
            return { ...state, items };
        },
    },
};
export default ResourceGroupModel;